from multiprocessing import Process, Queue
import time

def one(q):
    # 测试进程
    for i in range(3):
        time.sleep(2)
        print('测试进程_one')
    # 测试进程通信
    num = [11,22,33,44]
    for n in num:
        q.put(n)
    print('进程one写入队列完成！')


def two(q):
    # 测试进程
    for i in range(3):
        time.sleep(2)
        print('测试进程_two')
    # 测试进程通信
    new_list = []
    while True:
        new_list.append(q.get())
        if q.empty():
            break  
    print("输出进程two读取进程one的数据！")
    print(new_list)


def main():
    # 用于进程通信
    q = Queue()
    # 设置进程
    p1 = Process(target=one, args=(q,))
    p2 = Process(target=two, args=(q,))
    p1.start()
    p2.start()


if __name__ == "__main__":
    main()  